import requests
from data import LoginData
import app


class Login:
    Authorization = dict()
    # 所有数据初始化
    def __init__(self):
        self.session = requests.session()
        self.Account,self.Authorization,self.AuthMethod,self.AuthURL = LoginData.LoginData().ReadAuthExcel()
        self.path,self.LoginMethod,self.Content_Type,self.appVersion,self.os,self.smDeviceId= LoginData.LoginData().ReadAppTokenPathExcel()
        Login.Authorization['authorization'] = self.Authorization
        self.LoginURL = "https://{}".format(app.base_login_url)+self.path
        print(self.LoginURL)
    # auth登录
    def AuthLogin(self):
        return self.session.post(url=self.AuthURL,data=self.Account,headers=Login.Authorization)
    # app登录，获取实际使用token
    def APPLogin(self,globalToken):
        headers = {'Content-Type':'{}'.format(self.Content_Type),'version':'{}'.format(self.appVersion)}
        data = {'appVersion':'{}'.format(self.appVersion),'globalToken':'{}'.format(globalToken),'os':'{}'.format(self.os),'smDeviceId':'{}'.format(self.smDeviceId)}
        return self.session.post(url=self.LoginURL,json=data,headers=headers)

if __name__ == '__main__':
    # aaa = Login().AuthLogin().json()
    aaa = Login().AuthLogin().json()
    mmm = aaa.get('access_token')
    # #aaa.get('access_token')
    # # globalToken1 = 'eyJhbGciOiJSUzI1NiIsImtpZCI6IkNlcnQiLCJwaS5hdG0iOiJmIn0.eyJzY29wZSI6WyJvcGVuaWQiLCJlbWFpbCIsInByb2ZpbGUiLCJjYXJlX2J5X3ZvbHZvOmZpbmFuY2lhbF9pbmZvcm1hdGlvbjppbnZvaWNlOnJlYWQiLCJjYXJlX2J5X3ZvbHZvOmZpbmFuY2lhbF9pbmZvcm1hdGlvbjpwYXltZW50X21ldGhvZCIsImNhcmVfYnlfdm9sdm86c3Vic2NyaXB0aW9uOnJlYWQiLCJjdXN0b21lcjphdHRyaWJ1dGVzIiwiY3VzdG9tZXI6YXR0cmlidXRlczp3cml0ZSIsInZlaGljbGU6YXR0cmlidXRlcyIsIm9yZGVyOmF0dHJpYnV0ZXMiLCJ2b2x2b19vbl9jYWxsOmFsbCJdLCJjbGllbnRfaWQiOiJhaFA3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